<template>
  <el-card>
    <el-form ref="formRef" :inline="true">
      <el-form-item label="一级分类">
        <el-select
          placeholder="请选择"
          style="width: 200px"
          v-model="categoryStore.c1Id"
          @change="getCategoryC2"
          :disabled="scene == 0 ? false : true"
        >
          <el-option
            v-for="c1 in categoryStore.c1Arr"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          placeholder="请选择"
          style="width: 200px"
          v-model="categoryStore.c2Id"
          @change="getCategoryC3"
          :disabled="scene == 0 ? false : true"
        >
          <el-option
            v-for="c2 in categoryStore.c2Arr"
            :label="c2.name"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          placeholder="请选择"
          style="width: 200px"
          v-model="categoryStore.c3Id"
          :disabled="scene == 0 ? false : true"
        >
          <el-option
            v-for="c3 in categoryStore.c3Arr"
            :label="c3.name"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import useCategoryStore from "@/store/modules/category.ts";
let categoryStore = useCategoryStore();
//接收父组件传递过来的参数
defineProps(["scene"]);
onMounted(() => {
  getCategoryC1();
});
//获取一级商品分类的数据
const getCategoryC1 = () => {
  //清除数据
  categoryStore.c2Id = "";
  categoryStore.c3Arr = [];
  categoryStore.c3Id = "";
  //通知仓库发请求获取以及分类的数据
  categoryStore.getC1();
};
//获取二级商品分类的数据
const getCategoryC2 = () => {
  categoryStore.c2Id = "";
  categoryStore.c3Arr = [];
  categoryStore.c3Id = "";
  categoryStore.getC2();
};
//获取三级商品分类的数据
const getCategoryC3 = () => {
  categoryStore.c3Id = "";
  categoryStore.getC3();
};
</script>

<style scoped></style>
